const ToolCloudCache = {};

class ToolCloud {
	constructor(cloudName = 'uni-id-cf') {
		this.cloudName = cloudName;
	}
	
	async send(action, params) {
		let res = await uniCloud.callFunction({
			name: this.cloudName,
			data: { action, params }
		})
		return res.result || res;
	}
}

const toolCloud = {
	init(cloudName = 'uni-id-cf') {
		return ToolCloudCache[cloudName] || (ToolCloudCache[cloudName] = new ToolCloud(cloudName));
	}
}

export default toolCloud;